import com.mic.yzzn.plc.common.control.RMI.PLCMaster;
import com.mic.yzzn.plc.core.control.PLCCollectorMasterImpl;
import com.mic.yzzn.plc.core.control.datastructure.PLCContext;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * Created by ASH on 16/4/16.
 */
public class PLCManager {
    private static final Logger logger = LogManager.getLogger(PLCManager.class);

    public static void main(String[] args) {
        PLCCollectorMasterImpl manager = null;
        try {
            manager = new PLCCollectorMasterImpl();
        } catch (RemoteException e) {
            e.printStackTrace();
        }

        try {
            LocateRegistry.createRegistry(1099);
        } catch (Exception e) {
            e.printStackTrace();
        }

        try {
            Naming.rebind(PLCMaster.NAME, manager);
        } catch (Exception e) {
            e.printStackTrace();
        }

        DOMConfigurator.configure("log4j.xml");
        manager.setContext(new PLCContext("", "PLC-Config.xml"));
        manager.getContext().setFromConfigXML();
        manager.getContext().rebindAllCollector();
        manager.getContext().fireAllCollector();
    }
}
